//
//  XWCell.m
//  SDAutoLayoutDemo
//
//  Created by xiewei on 16/6/19.
//  Copyright © 2016年 xiewei. All rights reserved.
//

#import "XWCell.h"
#import "UIView+SDAutoLayout.h"

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

@interface XWCell()

@property (nonatomic,weak) UILabel *lab;

@end

@implementation XWCell

+ (instancetype)xwcellWithTableView:(UITableView *)tableview {
    NSString *reuseID = @"xwcell";
    XWCell *cell = [tableview dequeueReusableCellWithIdentifier:reuseID];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        /// 创建子控件
        UILabel *lab = [[UILabel alloc] init];
        lab.numberOfLines = 0;
        self.lab = lab;
        
        /// 添加子控件到contentView上
        [self.contentView sd_addSubviews:@[lab]];
        
        /// 设置frame
        /// 设置自适应高度步骤：
        /// 1）autoHeightRatio(0)（cell自适应高度步骤1）
        self.lab.sd_layout.widthIs(SCREEN_WIDTH).leftSpaceToView(self.contentView,0).topSpaceToView(self.contentView,0).autoHeightRatio(0);
        
        /// 2）cell自适应高度步骤2
        [self setupAutoHeightWithBottomView:self.lab bottomMargin:10];
    }
    return self;
}
- (void)setText:(NSString *)text {
    _text = text;
    
    /// 给子控件赋值
    self.lab.text = _text;
    
    /// 设置frame
//    self.lab.sd_layout
}
//- (void)layoutSubviews {
//    [super layoutSubviews];
//    
//    
//}

@end
